package com.alfred.mall.miaosha.controller;

import com.alfred.mall.miaosha.api.MiaoshaGoodsServcie;
import com.alfred.mall.miaosha.api.bo.MiaoshaGoodsBO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 秒杀商品
 */
@Controller
@RequestMapping("/page")
public class MiaoshaPageController {

    @Reference(validation = "true")
    MiaoshaGoodsServcie miaoshaGoodsServcie;

    /**
     * 秒杀商品列表
     *
     * @param model
     * @return
     */
    @GetMapping("/goods/list")
    public String goodsList(Model model) {
        List<MiaoshaGoodsBO> list = miaoshaGoodsServcie.selectAllMiaoshaGoods();
        model.addAttribute("goodslist", list);
        return "goods_list";
    }

    @GetMapping(value = "/detail")
    public String detail(Model model, @RequestParam("goodsId") Integer goodsId, HttpServletRequest request) {
        MiaoshaGoodsBO goods = miaoshaGoodsServcie.selectMiaoshaGoodsById(goodsId);
        model.addAttribute("goods", goods);
        return "goods_detail";
    }
}
